<?php
global $IP;
if( !defined( 'MEDIAWIKI' ) )
	die(-1);

require_once('DatabaseFunctions.php');
require_once("$IP/extensions/Tops/tops.php");

$wgExtensionCredits['specialpage'][] = array(
	'name' => 'TopArtists',
	'author' => 'mp2p',
);


#install extension hook
$wgAjaxExportList[] = 'wfAjaxTopArtist';
$wgExtensionFunctions[] = "wfSpecialPageTopArtists";

function wfAjaxTopArtist($type, $page){
	return $page."#".renderTops($type, $page);
}

function wfSpecialPageTopArtists()
{
	SpecialPage::addPage( new TopArtists() );
}


class TopArtists extends SpecialPage
{
	function TopArtists(){
		SpecialPage::SpecialPage("TopArtists");
		self::loadMessages();
		return true;
		
	}
	
	function loadMessages() {
       static $messagesLoaded = false;

       global $wgMessageCache;
       if ($messagesLoaded) return;
       $messagesLoaded = true;

       $allMessages = array(
           'en' => array(
               'sphinxPreviousPage'       => '10 Less',
               'sphinxNextPage'           => '10 More'
           )
       );

       foreach ( $allMessages as $lang => $langMessages ) {
           $wgMessageCache->addMessages( $langMessages, $lang );
       }
       return true;
   }

	function execute() {
       		global $wgOut;
		$wgOut->setDefaultTitle('Top Artists');
		$wgOut->setPagetitle("Top Artists");
		$this->renderTopArtists();
	}
	
	
	
	function renderTopArtists() {
		global $wgScript, $wgRequest, $wgOut, $wgScriptPath;
		
		$wgOut->addScript("<script type=\"text/javascript\" src=\"/skins/soundshare/tops.js\"></script>\n");
		$wgOut->addHTML( '<div class="tops">');
		$wgOut->addHTML( '<input type="hidden" id="page" value="1">');
		$wgOut->addHTML('<div class="tops-popular">Popularity</div>');
		$output.="<div id='panel-topArtist1'></div>";
		$output .="</div>";
		$wgOut->addHTML($output);
		$this->createNextPageBar($page, 1000,$rowsByPage); 
		$output="<script>document.getElementById('page').value=1;moreArtists()</script>";
		$wgOut->addHTML($output);
	}
 

	function createNextPageBar($page, $found, $rowsByPage) {
		global $wgOut,$wgRequest,$wgScript;
	
		$qry="javascript:moreArtists()";
				
		$next_page = '<div style="text-align:center;margin-top:20px">';
		$next_page.= '<div class="button-grey"><div class="button-grey-start"></div>';
		$next_page .= '<a href="'.$qry;
		$next_page .= '">[+]' . wfMsg('sphinxNextPage') .'</a>';
		$next_page .= '<div class="button-grey-end"></div></div>';
		$next_page .='<img id="loader_tops"  src="/skins/soundshare/loader_tops.gif">';
		$next_page .= '<div style="padding-bottom:35px"></div></div> ';
		
		$wgOut->addHTML($next_page);
				
			
	}
}

	

	

